package com.wky.basic.service.impl;

import com.wky.basic.Result.PageResult;
import com.wky.basic.mapper.BaseMapper;
import com.wky.basic.service.BaseService;
import com.wky.org.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class BaseServiceImpl<T> implements BaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    /**
     * 查询所有
     * @return
     */
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    /**
     * 分页查询
     * @param t
     * @return
     */
    @Override
    public PageResult<T> findByPage(T t) {
        //分页数据
        List<T> data = baseMapper.findByPage(t);
        //总条数
        Integer total = baseMapper.findTotal(t);

        //封装返回
        return new PageResult<T>(total,data);
    }

    /**
     * 添加
     * @param t
     */
    @Override
    public void add(T t) {
        baseMapper.add(t);
    }

    /**
     * 修改
     * @param t
     */
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }
}
